package logic

import (
	"context"
	"fresh-box/models/mysql"

	"fresh-box/freshrpc/freshrpc"
	"fresh-box/freshrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type FreshListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFreshListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FreshListLogic {
	return &FreshListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 列表
func (l *FreshListLogic) FreshList(in *freshrpc.FreshListRequest) (*freshrpc.FreshListResponse, error) {
	// todo: add your logic here and delete this line

	var fresh mysql.Fresh
	var lists []*freshrpc.FreshList

	lists, err := fresh.FreshList(mysql.DB, in, lists)
	if err != nil {
		return nil, err
	}

	return &freshrpc.FreshListResponse{
		List: lists,
	}, nil
}
